<%--
  Created by IntelliJ IDEA.
  User: 王辉
  Date: 2022/5/10
  Time: 17:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<% request.setCharacterEncoding("UTF-8");%>
<html>
<head>
    <title>修改名片...</title>
</head>
<body>
<%
    Integer cid = Integer.parseInt(request.getParameter("cid"));
    session.setAttribute("cid",cid);
    String driverName="com.mysql.cj.jdbc.Driver";
    String username = "root";
    String password = "123456";
    String url = "jdbc:mysql://localhost:3306/t_card?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false";
    Class.forName(driverName);
    Connection conn = DriverManager.getConnection(url,username,password);
    String sql = "select * from cuser where cid = ? and uid = ? and isdeleted = 0";
    String sql2 = "select id from user where username = ?";
    PreparedStatement pstmt = conn.prepareStatement(sql);
    PreparedStatement pstmt2 = conn.prepareStatement(sql2);
    String userName = (String) session.getAttribute("username");
    pstmt2.setString(1,userName);
    ResultSet rs1 = pstmt2.executeQuery();
    String uid = "";
    while (rs1.next()){
        uid = rs1.getString("id");
    }
    pstmt.setInt(1,cid);
    pstmt.setString(2,uid);
    ResultSet rs = pstmt.executeQuery();
    List list = new ArrayList<>();
    while (rs.next()){
        list.add(rs.getInt("cid"));
        list.add(rs.getString("cname"));
        list.add(rs.getString("csex"));
        list.add(rs.getString("cphone"));
        list.add(rs.getString("cemail"));
    }
%>

<div align="center">
    <br><br>
    <h1 style="color: coral">修改名片</h1>
    <br><br><br>
</div>
<br><br><br>
<div align="center" style="width: auto">
    <form action="updated.jsp" method="post">
        备注名:<input name="cUserName" type="text" value="<%=list.get(1)%>"><br><br>
        <%if(list.get(2).equals("男")){%>
        性&nbsp;&nbsp;&nbsp;&nbsp;别:<input name="cSex" type="radio" checked="checked">男 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="cSex" type="radio">女<br><br>
        <%}else {%>
        性&nbsp;&nbsp;&nbsp;&nbsp;别:<input name="cSex" type="radio">男 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="cSex" type="radio"  checked="checked">女<br><br>
        <%}%>
        手机号:<input name="cPhone" type="text" value="<%=list.get(3)%>"><br><br>
        邮&nbsp;&nbsp;&nbsp;&nbsp;箱:<input name="cEmail" type="text" value="<%=list.get(4)%>"><br><br>
        <input type="submit" value="修改"> &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="reset" value="重置">
    </form>
</div><br>
<div align="center">
    <a href="index.jsp" style="color: crimson">返回主页</a>
</div>
</body>
</html>
